import { createRouter, createWebHistory } from "vue-router";
const routerHistory = createWebHistory();


import Layout from "@/layout/index.vue";
export const constantRoutes = [
  {
    path: "/redirect",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "/redirect/:path(.*)",
        component: () => import("@/views/redirect/index"),
      },
    ],
  },
  {
    path: "/login",
    component: () => import("@/views/login"),
    hidden: true,
  },
  {
    path: "/auth-redirect",
    component: () => import("@/views/login/auth-redirect"),
    hidden: true,
  },
  {
    path: "/",
    component: Layout,
    redirect: "/index",
    meta: { title: "流程信息", icon: "dashboard",activeMenu:'/' },
    children: [
      {
        path: "/index",
        component: () => import("@/views/dashboard/index"),
        name: "Index",
        meta: { title: "首页", icon: "dashboard", affix: true,activeMenu:'/index' },
      },
      {
        path: "/flowEdit",
        name: "flowEdit",
        component: () => import("@/views/FlowDetail.vue"),
        hidden: true,
        meta: { title: "流程编辑", icon: "Box", show: true, isFrame: false,activeMenu:'/flowDetail' },
      },
      {
        path: "/flowAdd",
        name: "flowAdd",
        component: () => import("@/views/FlowDetail.vue"),
        hidden: true,
        meta: { title: "流程添加", icon: "Box", show: true, isFrame: false,activeMenu:'/flowDetail' },
      },
    ],
  },{
    path: "/flowCreate",
    component: Layout,
    redirect: "/flowCreate",
    meta: { title: "审批列表", icon: "list",activeMenu:'/' },
    children: [
      {
        path: "/flowCreate",
        component: () => import("@/views/flowCreateList"),
        name: "flowCreate",
        meta: { title: "审批列表", icon: "list", affix: false,activeMenu:'/flowCreate' },
      },
    ]
  },
  {
    path: "/flowToDo",
    component: Layout,
    redirect: "/flowToDo",
    meta: { title: "我的待办", icon: "todo",activeMenu:'/' },
    children: [
      {
        path: "/flowToDo",
        component: () => import("@/views/flowToDoList"),
        name: "flowToDo",
        meta: { title: "我的待办", icon: "todo", affix: false,activeMenu:'/flowToDo' },
      },
    ]
  },
  {
    path: "/flowDone",
    component: Layout,
    redirect: "/flowDone",
    meta: { title: "我的已办", icon: "done",activeMenu:'/' },
    children: [
      {
        path: "/flowDone",
        component: () => import("@/views/flowDoneList"),
        name: "flowDone",
        meta: { title: "我的已办", icon: "done", affix: false,activeMenu:'/flowDone' },
      },
    ]
  },
  {
    path: "/flowFrom",
    component: Layout,
    redirect: "/flowFrom",
    meta: { title: "流程表单", icon: "flow",activeMenu:'/' },
    children: [
      {
        path: "/flowFrom",
        component: () => import("@/views/FlowFrom"),
        name: "flowFrom",
        meta: { title: "流程表单", icon: "flow", affix: false ,activeMenu:'/flowFrom'},
      },
    ]
  }
];

const router = createRouter({
  history: routerHistory,
  routes:  constantRoutes,
  // 刷新时，滚动条位置还原
  scrollBehavior: () => ({ left: 0, top: 0 }),
  // scrollBehavior(to, from, savedPosition) {
  //   if (savedPosition) {
  //     return savedPosition
  //   } else {
  //     return { top: 0 }
  //   }
  // },
});
export default router;
